package edu.bw.service.impl;

import edu.bw.dao.ProductDao;
import edu.bw.po.Product;
import edu.bw.utils.TransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductServiceImpl02 {
    @Autowired
    private ProductDao productDao;
    @Autowired
    private TransactionManager transactionManager;
    public void updateProduct(Product product) {
//        transactionManager.beginTransaction();
//        try {
//            productDao.updateProduct(product);
//            transactionManager.commit();
//        } catch (Exception e) {
//            e.printStackTrace();
//            transactionManager.rollback();
//        }
//        transactionManager.close();
        productDao.updateProduct(product);
    }

    public void deleteProductById(int pid) {
//        transactionManager.beginTransaction();
//        try {
//            productDao.deleteProductById(pid);
//            transactionManager.commit();
//        } catch (Exception e) {
//            transactionManager.rollback();
//        }
//        transactionManager.close();
        productDao.deleteProductById(pid);
    }


    public List<Product> findAllProducts() {
        return productDao.findAllProducts();
    }
}
